// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext();
  let openid = wxContext.OPENID;
  let card_id = event.card_id;
  let status = event.status;
  let update_time = new Date();
  try {
    return await db.collection('ops_card').where({
      _id: card_id,
      Issuer_openid: openid
    }).update({
      data: {
        status: status,
        update_time: update_time,
      },
    })
  } catch (error) {
    console.log(error);
  }
}